import * as vscode from 'vscode';

// 树节点
export class EntryItem extends vscode.TreeItem {
}

interface WebItemOptions {
  command: string;
  title: string;
  arguments?: Array<String>
}

// 节点
export class WebItem extends EntryItem {
  constructor(label: string | vscode.TreeItemLabel, options: WebItemOptions, collapsibleState?: vscode.TreeItemCollapsibleState | undefined){
    super(label, collapsibleState);
    // 命令
    // this.command = {
    //   command: options.command,
    //   title: options.title,
    //   arguments: options.arguments //命令接收的参数
    // };
    this.command = options;
  }
}

//树的内容组织管理
export class EntryList implements vscode.TreeDataProvider<EntryItem>
{
  onDidChangeTreeData?: vscode.Event<void | EntryItem | null | undefined> | undefined;
  getTreeItem(element: EntryItem): vscode.TreeItem | Thenable<vscode.TreeItem> {
    return element;
  }
  getChildren(element?: EntryItem): vscode.ProviderResult<EntryItem[]> {
    if (element) {//子节点
      var childs = [];
      for (let index = 0; index < 3; index++) {
        let str = index.toString();
        var item = new EntryItem(str, vscode.TreeItemCollapsibleState.None);
        item.command = {
          command: "helloPlugin-tools.openChild", //命令id
          title: "标题",
          arguments: [str] //命令接收的参数
        };
        childs[index] = item;
      }
      return childs;
    } else { //根节点
      
      // const testView = new WebItem("展示页", {
      //   command: "hello.openWebview", //命令id
      //   title: '展示',
      //   arguments: ['123']
      // }, vscode.TreeItemCollapsibleState.None);

      return [
        new WebItem("展示页", {
          command: "hello.openWebview", //命令id
          title: '展示',
          arguments: ['123']
        }, vscode.TreeItemCollapsibleState.None),
        
        new WebItem("表单页", {
          command: "hello.webFormGen", //命令id
          title: '表单页',
          arguments: []
        }, vscode.TreeItemCollapsibleState.None),


        new EntryItem("root", vscode.TreeItemCollapsibleState.Collapsed),
      ];
    }
  }
}